package net.es.lookup.scalability.testing;

import java.util.List;

public class MessengerPool {

    private MessengerThread[] messengerPool;

    public MessengerPool(String user, List<List<String>> hosts, String workingDir, String resultRepo, String fileLoc, String sshKeyFile, String password) {


        System.out.println("Starting " + hosts.size() + " threads to connect to hosts");
        messengerPool = new MessengerThread[hosts.size()];

        for (int i = 0; i < hosts.size(); i++) {

            messengerPool[i] = new MessengerThread(user, hosts.get(i), workingDir, resultRepo, fileLoc, sshKeyFile, password);
            if (messengerPool[i].isConnected()) {

                System.out.println("Starting thread " + i);
                messengerPool[i].start();

            } else {

                return;
            }
        }
    }

    public void disconnect() {

        for (int i = 0; i < messengerPool.length; i++) {

            messengerPool[i].disconnect();
        }
    }
}